package com.bah.tract.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
public class Person {

	private long id;

	private String firstName;

	private String lastName;

	private int boozAllenID;

	private String cn;

	private byte[] certificate;

	@Lob
	public byte[] getCertificate() {
		return certificate;
	}

	public void setCertificate(byte[] certificate) {
		this.certificate = certificate.clone();
	}

	@Column(unique = true, nullable = false)
	public String getCn() {
		return cn;
	}

	public void setCn(String cn) {
		this.cn = cn;
	}

	@Column(name = "booz_id", unique = true, nullable = false)
	public int getBoozAllenID() {
		return boozAllenID;
	}

	public void setBoozAllenID(int boozAllenID) {
		this.boozAllenID = boozAllenID;
	}

	@Column(name = "first_name")
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column(name = "last_name")
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	private Person manager;

	@OneToOne
	public Person getManager() {
		return manager;
	}

	public void setManager(Person manager) {
		this.manager = manager;
	}

	public List<Person> directReports;

	@OneToMany(mappedBy = "manager", fetch = FetchType.LAZY)
	public List<Person> getDirectReports() {
		return directReports;
	}

	public void setDirectReports(List<Person> directReports) {
		this.directReports = directReports;
	}

	public List<Project> projects;

	@ManyToMany(fetch = FetchType.LAZY, mappedBy = "projectManagers")
	public List<Project> getProjects() {
		return projects;
	}

	public void setProjects(List<Project> projects) {
		this.projects = projects;
	}

	private List<Role> roles;


	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "person_role", joinColumns = @JoinColumn(name = "person_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
	public List<Role> getRoles() {
		return roles;
	}

	/**
	 * Setter of the property <tt>roles</tt>
	 * @param roles  The roles1 to set.
	 * @uml.property  name="roles"
	 * @uml.associationEnd  multiplicity="(0 -1)" ordering="true" inverse="person:com.bah.tract.model.Role"
	 */
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}


}
